/* eslint-disable jsdoc/no-restricted-syntax */
"use strict";

const fs = require("node:fs");
const path = require("node:path");
const opml = require("opml");

const pwd = process.cwd();
const filePath = path.resolve(pwd, "./SPEC.opml");
const writeFilePath = path.resolve(pwd, "./index.json");

console.log("read file:", filePath);
fs.readFile(filePath, (err, opmltext) => {
  if (!err) {
    opml.parse(
      opmltext,
      (/** @type {any} */ err, /** @type {any} */ theOutline) => {
        if (!err) {
          console.log(JSON.stringify(theOutline, undefined, 2));
          fs.writeFileSync(
            writeFilePath,
            JSON.stringify(theOutline, undefined, 2),
          );
          console.log("fin.");
        }
      },
    );
  }
});
